package ControlLayer;
import ModeLayer.*;

/**
 * Write a description of class CtrlForestOwner here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ForestOwnerCtr
{
   private ContainerForest myForest;
   private ContainerOwner myOwner;

    /**
     * Constructor for objects of class CtrlForestOwner
     */
    public ForestOwnerCtr()
    {
        myForest = ContainerForest.getInstance();
        myOwner = ContainerOwner.getInstance();
    }
    public void addForest(String NewName, String NewLocation, double NewSquareMetre, String NewNatureOfTrees,
                          double NewPricePrSquareMetre)
    {
     Forest forestObj = new Forest( NewName,  NewLocation,  NewSquareMetre, NewNatureOfTrees,  NewPricePrSquareMetre);
     myForest.addForest(forestObj);
    }
    
    public void addOwner(String newOwnerName, String newAddress, int newPhoneNumber)
    {
        Owner ownerObj = new Owner( newOwnerName,  newAddress, newPhoneNumber);
        myOwner.addOwner (ownerObj);
    }
    public Forest findForest(String forestName)
    {
        return myForest.findForest(forestName);
    }
    public Owner findOwner(String ownerName)
    {
        return myOwner.findOwner(ownerName);
    }
    public void addOwnerToForest(String ownerName, String forestName) throws Exception
    {
        Owner ownerObj = findOwner(ownerName);
        if(ownerObj == null)
        {
            throw new Exception("Owner not found");
        }
        Forest forestObj = findForest(forestName);
        if(forestObj == null)
        {
            throw new Exception("Forest not found");
        }
        forestObj.addOwner(ownerObj);
    }
     public void SetTreeSpecies(String forestName, String speci, int life, double cost, double earn, int pct)throws Exception   
    {
        Forest forestObj = findForest(forestName);
        if(forestObj == null)
        {
            throw new Exception("Forest not found");
        }
        Tree treeObj = new Tree(speci, life, cost, earn);
     
        forestObj.addTree(treeObj);
    }
}
